package o;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageInfo;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.foundation.ui.framework.widget.button.DownloadButton;
import com.huawei.appgallery.share.api.ShareBean;
import com.huawei.appgallery.share.protocol.SnsShareDialogActivityProtocol;
import com.huawei.appgallery.share.protocol.SnsShareDialogActivityProtocol.Request;
import com.huawei.hms.api.HuaweiApiAvailability;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import o.cwj.d;
import o.cwj.i;

public class cxl extends cxg {
    private Bitmap ʻ;
    private boolean ʼ;
    private BroadcastReceiver ʽ = new BroadcastReceiver(this) {
        final /* synthetic */ cxl ˋ;

        {
            this.ˋ = r1;
        }

        public void onReceive(Context context, Intent intent) {
            if (this.ˋ.ॱ != null) {
                this.ˋ.ॱ.ॱ();
            }
        }
    };
    private PackageInfo ˊ;
    private ShareBean ˋ;
    private boolean ˎ;
    private cxi ˏ;
    private DownloadButton ॱ;

    class b extends AsyncTask<Void, Void, byte[]> {
        final /* synthetic */ cxl ˊ;
        private Bitmap ˎ;
        private Context ˏ;
        private Bitmap ॱ;

        protected /* synthetic */ Object doInBackground(Object[] objArr) {
            return ˎ((Void[]) objArr);
        }

        protected /* synthetic */ void onPostExecute(Object obj) {
            ॱ((byte[]) obj);
        }

        public b(cxl o_cxl, Context context, Bitmap bitmap, Bitmap bitmap2) {
            this.ˊ = o_cxl;
            this.ˏ = context;
            this.ॱ = bitmap;
            this.ˎ = bitmap2;
        }

        protected byte[] ˎ(Void... voidArr) {
            if (this.ॱ != null) {
                this.ॱ = cxw.ˊ(this.ॱ, cwv.ॱ().ˎ());
            }
            if (this.ˊ.ˋ.ˊॱ() != 3 || (this.ˊ.ˊ != null && this.ˊ.ˊ.versionCode < HuaweiApiAvailability.HMS_VERSION_CODE_OD)) {
                return cxw.ˎ(this.ˏ, this.ˎ, this.ˊ.ˋ.ˏ(), 30, cxw.ˏ(this.ˊ.ˋ.ˋ()));
            }
            return cxw.ˎ(this.ˏ, this.ॱ, this.ˊ.ˋ.ˏ(), 30, cxw.ˏ(cwv.ॱ().ˊ()));
        }

        protected void ॱ(byte[] bArr) {
            String ॱ;
            String encode;
            boolean z = (TextUtils.isEmpty(this.ˊ.ˋ.ॱॱ()) || 2 == this.ˊ.ˋ.ॱˊ() || 1 == this.ˊ.ˋ.ॱˊ() || "Reserve".equals(this.ˊ.ˋ.ʽ())) ? false : true;
            if ("Reserve".equals(this.ˊ.ˋ.ʽ()) || "orderappdetail".equals(this.ˊ.ˋ.ʽ()) || z) {
                ॱ = cxw.ॱ(this.ˏ, this.ˊ.ˋ.ʻ(), "hwid");
                try {
                    encode = URLEncoder.encode(ॱ, "UTF-8");
                } catch (UnsupportedEncodingException e) {
                    cwr.ॱ.ˊ("HwIdShareHandler", "can not encode url");
                    encode = ॱ;
                }
                encode = "hiapp://com.huawei.appmarket?activityName=activityUri|webview.activity&params={\"params\":[{\"name\":\"url\",\"type\":\"String\",\"value\":\"" + encode + "\"},{\"name\":\"uri\",\"type\":\"String\",\"value\":\"external_webview\"}]}&channelId=123412";
            } else {
                ॱ = cxw.ॱ(this.ˏ, this.ˊ.ˋ.ʻ(), "hwid");
                encode = ॱ;
            }
            if ("orderappdetail".equals(this.ˊ.ˋ.ʽ())) {
                encode = "hiapp://com.huawei.appmarket?activityName=activityUri|appdetail.activity&params={\"params\":[{\"name\":\"uri\",\"type\":\"String\",\"value\":\"orderappdetail|" + this.ˊ.ˋ.ᐝ() + "\"}]}&channelId=123412";
            } else if (z) {
                encode = "hiapp://com.huawei.appmarket?activityName=activityUri|appdetail.activity&params={\"params\":[{\"name\":\"uri\",\"type\":\"String\",\"value\":\"package|" + this.ˊ.ˋ.ॱॱ() + "\"}]}&channelId=123412";
            }
            cjo snsShareDialogActivityProtocol = new SnsShareDialogActivityProtocol();
            Request request = new Request();
            request.ॱ(bArr);
            String ˊ = this.ˊ.ˋ.ˊ();
            if ("appdetail".equals(this.ˊ.ˋ.ʼ())) {
                ˊ = this.ˏ.getString(i.ˊˊ, new Object[]{cwv.ॱ().ˋ()});
            }
            if (this.ˊ.ˋ.ˊॱ() == 3 && !TextUtils.isEmpty(this.ˊ.ˋ.ˊ())) {
                request.ˊ(cxw.ˎ(this.ˏ, this.ˎ, this.ˊ.ˋ.ˏ(), 4, cxw.ˏ(this.ˊ.ˋ.ˋ())));
                ॱ = "hwfastapp://" + this.ˊ.ˋ.ॱॱ();
                ˊ = this.ˊ.ˋ.ˊ();
                request.ˊ(true);
                encode = ॱ;
            }
            request.ˊ(ˊ);
            request.ˏ(this.ˊ.ˋ.ॱ());
            request.ˎ(encode);
            request.ˋ(ॱ);
            snsShareDialogActivityProtocol.ˋ(request);
            cjk.ˎ().ˋ(this.ˏ, new cjm("sns_share_dialog.activity", snsShareDialogActivityProtocol));
            this.ˊ.ˏ.finish();
        }
    }

    class c implements eqz {
        final /* synthetic */ cxl ॱ;

        private c(cxl o_cxl) {
            this.ॱ = o_cxl;
        }

        public void ॱ(Bitmap bitmap) {
            if (this.ॱ.ʼ) {
                cwr.ॱ.ˋ("HwIdShareHandler", "activity is destroy.");
                return;
            }
            Bitmap copy;
            if (bitmap != null) {
                copy = bitmap.copy(Config.ARGB_8888, true);
                cwr.ॱ.ˋ("HwIdShareHandler", "hwid get net bitmap success!");
            } else {
                copy = BitmapFactory.decodeResource(this.ॱ.ˏ.ᐝ().getResources(), cwj$b.ˏ);
                cwr.ॱ.ˋ("HwIdShareHandler", "hwid get net bitmap failed!");
            }
            this.ॱ.ˎ(this.ॱ.ˏ.ᐝ(), copy);
        }
    }

    public String ˎ() {
        return "com.huawei.hwid";
    }

    public boolean ˊ(ShareBean shareBean) {
        return super.ॱ(shareBean.ͺ(), 1, shareBean.ˏॱ());
    }

    public boolean ˏ(cxi o_cxi, LinearLayout linearLayout, LayoutInflater layoutInflater, boolean z, ShareBean shareBean) {
        this.ˏ = o_cxi;
        this.ˋ = shareBean;
        View inflate = layoutInflater.inflate(d.ˊ, null);
        ((TextView) inflate.findViewById(o.cwj.c.ˋ)).setText(i.ᐝॱ);
        ((ImageView) inflate.findViewById(o.cwj.c.ॱ)).setImageResource(cwj$b.ॱ);
        this.ॱ = (DownloadButton) inflate.findViewById(o.cwj.c.ʽ);
        this.ॱ.setVisibility(8);
        o_cxi.ˋ(ˎ(), this.ॱ);
        this.ˊ = dnx.ˏ("com.huawei.hwid", this.ˏ.ᐝ());
        linearLayout.addView(inflate);
        inflate.setOnClickListener(new OnClickListener(this) {
            final /* synthetic */ cxl ॱ;

            {
                this.ॱ = r1;
            }

            public void onClick(View view) {
                evc.ˊ(view);
                dgh.onEvent(new dge.d(ContentManager.getInstant().getContext(), i.ˎ).ˏ("05|" + UserSession.getInstance().getUserId() + '|' + this.ॱ.ˋ.ʻ()).ˋ());
                this.ॱ.ˋ(this.ॱ.ˏ.ᐝ());
            }
        });
        this.ˏ.registerReceiver(this.ʽ, new IntentFilter(ccv.ˋ()));
        return true;
    }

    private void ˋ(Context context) {
        cxi$d ᐝॱ = this.ˏ.ᐝॱ();
        if (ᐝॱ.ˏ()) {
            cwr.ॱ.ˋ("HwIdShareHandler", "click share to hwid friend!");
            this.ʻ = ᐝॱ.ॱ();
            ॱ(context);
            return;
        }
        cwr.ॱ.ˋ("HwIdShareHandler", "App Icon loading.");
        this.ˎ = true;
        this.ˏ.ͺ();
    }

    private void ॱ(Context context) {
        if (!dok.ͺ()) {
            cwr.ॱ.ˋ("HwIdShareHandler", "no available network.");
            evk.ˋ(context, context.getString(i.ʻ), 0).ˋ();
        } else if (this.ˋ.ˊॱ() != 3 || this.ˊ == null || this.ˊ.versionCode < HuaweiApiAvailability.HMS_VERSION_CODE_OD) {
            ˎ(this.ˏ.ᐝ(), null);
        } else {
            eqx.ॱ(this.ˏ.ᐝ(), cwv.ॱ().ˊ(), new c());
        }
    }

    public void ˎ(ShareBean shareBean) {
        if (this.ʽ != null) {
            this.ʼ = true;
            this.ˏ.unregisterReceiver(this.ʽ);
        }
    }

    public void ˏ() {
        this.ˎ = false;
    }

    public void ॱ() {
        if (this.ˎ) {
            this.ʻ = this.ˏ.ᐝॱ().getAttValueTypeName();
            ॱ(this.ˏ.ᐝ());
        }
    }

    private void ˎ(Context context, Bitmap bitmap) {
        cwr.ॱ.ˋ("HwIdShareHandler", "snsShare");
        new b(this, context, bitmap, this.ʻ).execute(new Void[0]);
    }
}
